package thread;

public class SyncDemo5 {
    public static void main(String[] args) {
        Aoo aoo = new Aoo();
        Thread t = new Thread(aoo::methodA);
        Thread t2 = new Thread(aoo::methodB);
        t.start();
        t2.start();

    }
}
    class Aoo{
        public  synchronized void methodA(){
            Thread t = Thread.currentThread();
            System.out.println(t.getName()+"正在执行A方法");
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
        public synchronized void methodB(){
            Thread t = Thread.currentThread();
            System.out.println(t.getName()+"正在执行B方法");
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }

